package aip.assignment2.persistence.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Stone
 */
@Entity
@Table(name = "person_title")
@XmlRootElement
@NamedQueries(
{
	@NamedQuery(name = "PersonTitle.findAll", query = "SELECT p FROM PersonTitle p"),
	@NamedQuery(name = "PersonTitle.findById", query = "SELECT p FROM PersonTitle p WHERE p.id = :id"),
	@NamedQuery(name = "PersonTitle.findByName", query = "SELECT p FROM PersonTitle p WHERE p.name = :name")
})
public class PersonTitle implements Serializable
{
	private static final long serialVersionUID = 1L;
	@Id
	@SequenceGenerator(name = "person_title_id", allocationSize = 1, sequenceName = "person_title_id_seq")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_title_id")
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 20)
	@Column(name = "name")
	private String name;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "title")
	private List<PersonName> personNameList;
	public PersonTitle()
	{
	}
	public PersonTitle(Integer id)
	{
		this.id = id;
	}
	public PersonTitle(Integer id, String name)
	{
		this.id = id;
		this.name = name;
	}
	public Integer getId()
	{
		return id;
	}
	public void setId(Integer id)
	{
		this.id = id;
	}
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	@XmlTransient
	public List<PersonName> getPersonNameList()
	{
		return personNameList;
	}
	public void setPersonNameList(List<PersonName> personNameList)
	{
		this.personNameList = personNameList;
	}
	@Override
	public int hashCode()
	{
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}
	@Override
	public boolean equals(Object object)
	{
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof PersonTitle))
		{
			return false;
		}
		PersonTitle other = (PersonTitle) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
		{
			return false;
		}
		return true;
	}
	@Override
	public String toString()
	{
		return "aip.assignment2.data.entity.PersonTitle[ id=" + id + " ]";
	}
}
